import userStore from '@/store/userStore'
import { Router, RouteRecordRaw } from 'vue-router'
import  {env} from'../../types/helper'
import autoloadModuleRoutes from './module'
import getRoutes from './view'



let routes:RouteRecordRaw[] =env.VITE_ROUTER_AUTOLOAD?getRoutes():autoloadModuleRoutes()

function  autoload(router:Router){
    const user =userStore()
//     //1. 通过权限过滤掉用户没有权限的路由
//     routes =routes.map(route=>{
//  route.children=route.children?.filter(r=>{
//     const permission=  r.meta?.permission
//     //设置了权限就拦截，没有直接放行
//     return permission?user.info?.permissions?.includes(permission):true
//  })
//  return route
//     })

    //2.注册路由
  routes.forEach(r=> router.addRoute(r))
    
}
export default autoload